﻿using System;
using System.Collections.Generic;
using FoundationClass.Data;
using FoundationClass.Entity;

namespace FoundationClass
{
    public static class SecurityHandler
    {
        public static User LogIn(String username, string password)
        {
            if (Authenticate(username, password)) return UserData.GetUser(username);
            else throw new Exception("ชื่อผู้ใช้หรือพาสเวิร์ดไม่ถูกต้อง");
        }

        private static bool Authenticate(String username, string password)
        {
            User user = UserData.GetUser(username);
            if (password.Equals(user.Password)) return true;
            else return false;
        }

        public static void LogOut()
        {
            
        }

        public static void AddNewUser(User user)
        {
            UserData.InsertUser(user);
        }

        public static void UpdateUser(User user)
        {
            UserData.UpdateUser(user);
        }

        public static void RemoveUser(string id)
        {
           UserData.DeleteUser(id);
        }

        public static User GetUser(string id)
        {
            return UserData.GetUser(id);
        }

        public static IList<User> GetAllUsers()
        {
            return UserData.GetAllUsers();
        }

        public static bool Exist(string  username)
        {
            return UserData.UserExist(username);
        }

    }
}
